/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Presentacion;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.JScrollPane;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.*;
import javax.swing.JTabbedPane;
import java.io.*;
/**
 *
 * @author charo
 */
//public class TableDemo extends JFrame {
    public class TableDemo extends javax.swing.JFrame{

    public TableDemo() {

         super("Ejemplo 3");
          

        DefaultTableModel myModel = new DefaultTableModel();
        myModel.addColumn("id");
        myModel.addColumn("Nombre");
        myModel.addColumn("AP");
        myModel.addColumn("AM");
        myModel.addColumn("fechanacimiento");
        myModel.addColumn("carnet");
        myModel.addColumn("sexo");
       
        JTable table = new JTable(myModel);
        table.setPreferredScrollableViewportSize(new Dimension(500, 150));
        


         
            BufferedReader br = null;
                try{
                    br = new BufferedReader(new FileReader("D:\\prueba\\prueba8.txt"));
                    String line = br.readLine();

                    for(int row = 0; row < 10 ; row++){
                        for(int column = 0; column<7 ;column++){


                                   while (line != null )
                                   {
                                     String [] rowfields = line.split("\\,");
                                      //return cadena.split("\\.");
                                     myModel.addRow(rowfields);
                                     line = br.readLine();
                                    }
                                   
                                }
                             }

                        }
                catch(Exception e)
                  {
                            System.out.println(e.getMessage());
                  }
        
        JTabbedPane panelInformacion = new JTabbedPane();
        JPanel panel1 = new JPanel();
        panel1.add( new JScrollPane( table ));
        panelInformacion.addTab( "Codigo", null, panel1, "Primer panel" );
        //agregar objeto JTabbedPane al contenedor
        getContentPane().add( panelInformacion );

        setSize( 500, 600 );
        setVisible( true );
    }
    /**
     * Creates new form TableDemo
     */
    //public TableDemo() {
       // initComponents();
  //  }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 800, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 800, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TableDemo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TableDemo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TableDemo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TableDemo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
          TableDemo aplicacion = new TableDemo();
	aplicacion.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
       // aplicacion.setDefaultCloseOperation( JFrame.WIDTH);
        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new TableDemo().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
}
